﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using PortalWeb.Core.Entity;
using PortalWeb.Core.IDao;
using PortalWeb.Core.IManager;

namespace PortalWeb.Business.Manager
{
    public sealed partial class FunctionManager : IFunctionManager
    {
        public async Task<Function[]> GetFunctionsByRolesAsync(string roles)
        {
            var result = await BaseRepository.FindAsync(p => p.RolesString.Contains(roles));
            return result.ToArray();
        }

        public async Task<Function> GetByUrlAsync(string actionUrl)
        {
            var result = await BaseRepository.FindAsync(p => p.ActionUrl == actionUrl);
            return result.FirstOrDefault();
        }

        public async Task<Function[]> GetByParentIdAsync(int? parentId, string sort = "", string order = "")
        {
            var result = await BaseRepository.FindAsync(p => p.ParentId == parentId);
            return result.ToArray();
        }
    }
}